package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//ShIndiFbblcdr 零售非保本理财日均导入
type ShIndiFbblcdr struct {
	ID    int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	SDATE time.Time `gorm:"column:SDATE"`
	EDATE time.Time `gorm:"column:EDATE"`
	CUID  int       `gorm:"column:CUID"`
	ZJHM  string    `gorm:"column:ZJHM"`
	RJ    float64   `gorm:"column:RJ"`
}

//TableName
func (ShIndiFbblcdr) TableName() string {
	return "SH_INDI_FBBLCRJ"
}

// BeforeCreate
func (u *ShIndiFbblcdr) BeforeCreate(tx *gorm.DB) (err error) {
	var cuid *int
	base.CHDB.Raw("select ID from T_INDI_CLIE where IDNO=?", u.ZJHM).Row().Scan(&cuid)
	if cuid == nil {
		err = fmt.Errorf("证件号码%s在系统中不存在！", u.ZJHM)
		return
	}
	u.CUID = *cuid
	return
}

//ShIndiFbblcdrEF 返回结构体
func ShIndiFbblcdrEF() base.EntityFunc {
	return func() interface{} {
		entity := ShIndiFbblcdr{}
		return &entity
	}
}

//ShIndiFbblcdrESF 返回结构体数组
func ShIndiFbblcdrESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ShIndiFbblcdr
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("ShIndiFbblcdr", base.NewDefaultDao(ShIndiFbblcdrEF(), ShIndiFbblcdrESF(), nil, "my"))
}
